#pragma once
#include <iostream>
#include <pthread.h>
using namespace std;

class Mutex
{
public:
    Mutex()
    {
        int n = pthread_mutex_init(&mutex, nullptr);
        (void)n;
    }
    void Lock()
    {
        pthread_mutex_lock(&mutex);
    }
    void Unlock()
    {
        pthread_mutex_unlock(&mutex);
    }
    pthread_mutex_t *Get()
    {
        return &mutex;
    }
    ~Mutex()
    {
        int n = pthread_mutex_destroy(&mutex);
    }

private:
    pthread_mutex_t mutex;
};

class LockGuard
{
public:
    LockGuard(Mutex &mutex)
        : _mutex(mutex)
    {
        _mutex.Lock();
    }
    ~LockGuard()
    {
        _mutex.Unlock();
    }

private:
    Mutex &_mutex;
};